/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jus.aor.mobilagent.kernel;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;

/**
 *
 * @author Rémi PIOTAIX <remi.piotaix@gmail.com>
 */
public class AgentInputStream extends ObjectInputStream {

    private ClassLoader loader;

    public AgentInputStream(InputStream in, ClassLoader loader) throws IOException {
        super(in);
        this.loader = loader;
    }

    @Override
    protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
        try {
            return super.resolveClass(desc);
        } catch (ClassNotFoundException e) {
            return loader.loadClass(desc.getName());
        }
    }
}
